<?php
header("content-type:text/html;charset=utf8");
//引入文件
include("../../PHPExcel-1.8/PHPExcel-1.8/Classes/PHPExcel.php");
//连接数据库
$db=new PDO("mysql:host=127.0.0.1;dbname=iwebshop;charset=utf8","root","root");
$sql="select * from iwebshop_yg";
// print_r($sql);die;
$res=$db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
// print_r($res);die;
//实例化一个phpexce
$excel=new PHPExcel();
//设置一个表格
$table=$excel->setActiveSheetIndex();
$table->setCellValue("A1","u_id");
$table->setCellValue("B1","u_name");
$table->setCellValue("C1","u_pwd");
$table->setCellValue("D1","u_pwd1");
$table->setCellValue("E1","u_zname");
$table->setCellValue("F1","u_price");
$i=2;
foreach ($res as $key => $value) {
	$table->setCellValue("A".$i,$value["u_id"]);
	$table->setCellValue("B".$i,$value["u_name"]);
	$table->setCellValue("C".$i,$value["u_pwd"]);
	$table->setCellValue("D".$i,$value["u_pwd1"]);
	$table->setCellValue("E".$i,$value["u_zname"]);
	$table->setCellValue("F".$i,$value["u_price"]);
	$i++;
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$objWriter->save('php://output');
exit;
 ?>